<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>文章设置</title>
    <script type="text/javascript">
      var sysMsgId;
      var sysMsgDS;
      
      Ext.onReady(function(){
        //文章设置---------------------------------------------------------
        Ext.define('SysMsgModel', {
          extend : 'Ext.data.Model',
          fields : [
            {
              name: 'id'
            },{
              name: 'title'
            },{
              name: 'is_new'
            },{
              name: 'sub_type'
            }, {
              name: 'created_at'
            }, {
              name: 'updated_at'
            }
          ]
        });
        
        var sysMsgDS = Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'SysMsgModel',
          proxy : {
            type : 'ajax',
            url: '/sys_msg/getAllSysMsgs',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          },
          pageSize : pageSize,
          autoLoad : true
        });
        
        var sysMsgGrid =  Ext.create('Ext.grid.Panel', {
          store: sysMsgDS,
          columns : [{
              header: 'id',
              dataIndex: 'id',
              width: 40
            }, {
              header: '标题',
              dataIndex: 'title',
              width:410
            }, {
              header: '文章类型',
              dataIndex: 'sub_type',
              width:110
            }, {
              header: '状态',
              dataIndex: 'is_new',
              renderer: readStatusRender,
              width:70
            },{
              header: '生成日期',
              dataIndex: 'created_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
              width: 130
            },{
              header: '阅读日期',
              dataIndex: 'updated_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
              width: 130
            }],
          selModel :Ext.create('Ext.selection.CheckboxModel'),
          width: screenWidth-190,
          height: 350,
          iconCls: 'icon-grid',
          //collapsible: true,
          //animCollapse: false,
          //frame: true,
          //title: '文章列表',
          bbar: Ext.create('Ext.toolbar.Paging', {
            pageSize: pageSize,
            store: sysMsgDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          })
        });

        sysMsgGrid.on('itemdblclick', function(gridPanel, record,item,index,e,options){
          sysMsgId = sysMsgDS.getAt(index).get('id');
          Ext.Ajax.request({
            url : '/sys_msg/getMsgById',
            success : function (result, request) {
              content.setValue(Ext.JSON.decode(result.responseText).info);
              sysMsgDS.load();
              //调用全局函数改变可读数值
              synUnreadSysMsg();
            },
            failure : function (result, request){
              Ext.MessageBox.show({
                title: '消息',
                msg: "通讯失败，请从新操作",
                buttons: Ext.MessageBox.OK,
                icon: Ext.MessageBox.WARNING
              });
            },
            method : 'GET',
            params : {
              id : sysMsgId
            }
          });
        });

        var content = new Ext.form.HtmlEditor({
          fieldLabel: '内容',
          name: 'content',
          height:335,
          width: screenWidth-190,
          anchor: '100%'
        });
        
        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
          width: screenWidth-165,
          height: screenHeight-215,
          frame:false,          
          layout: {type: 'table',columns:1},          
          items:[sysMsgGrid,content]
        });
        
        workbenchPanel.render("sysMsg_list_workbench");
        
      })
    </script>
  </head>
  <body>
    <div id="sysMsg_list_workbench"></div>
  </body>
</html>
